package Control;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import Entity.MsgPackage;
import Entity.User;
import GUI.UpdateAuthGui;
import GUI.ScreenManager;

public class UpdateAuthControl {
	private UpdateAuthGui upAuthGui;
	private MsgPackage updateAuthMsg;
	private User user;
	
	public UpdateAuthControl(){
		upAuthGui= new UpdateAuthGui();
		updateAuthMsg= new MsgPackage(); 
		user= new User();
	}
	
	public UpdateAuthGui getUpAuthGui(){
		return upAuthGui;
	}
	
	public boolean updateAuthorization_pressed(){
		String x =upAuthGui.getTextArea_userName().getText();
		String y =upAuthGui.getTextArea_newAuth().getText();
		if((x==null)||y==null ){
			JOptionPane.showMessageDialog(null, "Not all the fileds all the fill", "ERROR", JOptionPane.ERROR_MESSAGE);
              return false;
		}
		user.setUserName(Integer.parseInt(upAuthGui.getTextArea_userName().getText()));
		user.setAuthorization(upAuthGui.getTextArea_newAuth().getText());
		updateAuthMsg.setObject(user);
		updateAuthMsg.setOp_code(OP_CODE.U);
		ScreenManager.getClient().accept(updateAuthMsg);
		JOptionPane.showMessageDialog(null, "The authrization updated successfully", "", JOptionPane.INFORMATION_MESSAGE);

		return true;
	}
} 
